package com.wing.qualityTesting.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.qualityTesting.dao.QualityTestingRecordValueDao;
import com.wing.qualityTesting.model.entity.QualityTestingRecordValue;
import com.wing.qualityTesting.model.request.QualityTestingRecordValueForm;
import com.wing.qualityTesting.model.response.QualityDetailValueInfoVo;
import com.wing.qualityTesting.model.response.QualityTestingRecordValueVO;
import com.wing.qualityTesting.model.response.WorkOrderQualityTestingTaskNeedVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 质检参数结果表-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class QualityTestingRecordValueServiceImpl extends ServiceImpl<QualityTestingRecordValueDao, QualityTestingRecordValue> implements QualityTestingRecordValueService {

    @Override
    public int add(QualityTestingRecordValueForm qualityTestingRecordValueForm) {

        //校验

        QualityTestingRecordValue qualityTestingRecordValue =new QualityTestingRecordValue();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(QualityTestingRecordValue.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(qualityTestingRecordValueForm, qualityTestingRecordValue, copyOptions);

        return baseMapper.insert(qualityTestingRecordValue);
    }

    @Override
    public List<QualityTestingRecordValueVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<QualityTestingRecordValueVO> pageList4app(Page page, Map<String, Object> params) {
        List<QualityTestingRecordValueVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public QualityTestingRecordValueVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }

    /**
     * 查询检测项
     * @param recordDetailId
     * @return
     */
    @Override
    public List<QualityDetailValueInfoVo> listRecordValues(Long recordDetailId) {
        return baseMapper.listRecordValues(recordDetailId);
    }

    @Override
    public WorkOrderQualityTestingTaskNeedVo getNeedInfoBy(Long qualityTestingTaskId) {
        return baseMapper.getNeedInfoBy(qualityTestingTaskId);
    }

    /**
     * 查询未质检的个数
     * @param id
     * @return
     */
    @Override
    public Integer getNoQualityCount(Long id) {
        return baseMapper.getNoQualityCount(id);
    }
}
